<?php
/**
 *投诉
 */
class ChapterController extends AdminBaseController {
	public function lists (){
		$chapter= HttpServerManager::getChapterServer();
		$data = $chapter->pagingBySearch($_GET);
		$course = HttpDaoManager::getCourseDao()->searchList();
		$tmp = array();
		foreach ($course as $v){
			$tmp[$v['id']] = $v['theme'];
		}
		$data['courseOption'] = $tmp;

		return $data;
	}
	public function add(){
		$data = array();
		if (!empty($_GET['id'])){
			$data = HttpDaoManager::getChapterDao()->get($_GET['id']);
		}
		$courseList = HttpDaoManager::getCourseDao()->searchList();
		$courses = array();
		foreach ($courseList as $v){
			$courses[$v['id']] = $v['theme'];
		}
		$data['courseOption'] =  page_modifier_options($courses,Common::getStrValue($data, 'course_id'));
		$status = Common::_t('course_status');

		$data['statusOption'] =  page_modifier_options($status,Common::getStrValue($data, 'status'));

		$ueditor = ClassManager::getUeditor();
		$content = Common::getStrValue($data, 'content');
		$data['ueditor_content'] = $ueditor->ueditor().$ueditor->ueditors_2('content',$content);

		$english_content = Common::getStrValue($data, 'english_content');
		$data['ueditor_english_content'] = $ueditor->ueditors_2('english_content',$english_content);

		$data['id'] = Common::getGetStrValue('id');
		return $data;
	}
	public function delete(){
		HttpServerManager::getChapterServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox("删除成功");
	}
	public function subAdd(){
		HttpServerManager::getChapterServer()->add($_POST);
		$msg = Common::_t('data_insert_success');
		ClassManager::getToos()->msgbox($msg);
	}
	public function subUpdate(){
		HttpDaoManager::getChapterDao()->update($_POST,$_POST['id']);
		$msg = Common::_t('data_edit_success');
		ClassManager::getToos()->msgbox($msg,'chapter_lists.html');
	}
	
	public function download(){
		$data = HttpDaoManager::getChapterDao()->get($_GET['id']);
		if(!empty($data)){
			$tmp = $data['document'];
			$new_file_name="";
			if($tmp!=""){
				$pos= strrpos($tmp,'/');
				$file_head = substr($tmp, 1,$pos);
				$file_name = substr($tmp, $pos+1);
				//$file_name = preg_replace('/\s{2, }| /','%20',$file_name);
				$new_file_name = $file_head.$file_name;
			}
			ClassManager::getToos()->download(WEB_DIR.$new_file_name);
			exit ;
		}
		exit ;
	}	
}
?>